package com.example.datasource;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.Test;

import javax.sql.DataSource;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Connection;
import java.util.Properties;

public class DruidTest {

    // 使用配置文件
    @Test
    public void testGetConnection() throws Exception {
        // 创建druid连接池
        Properties properties = new Properties();
        properties.load(Files.newInputStream(Paths.get("src/main/resources", "druid.properties")));
        DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);

        // 获取连接
        Connection connection = dataSource.getConnection();
        System.out.println(connection);
    }

}
